<?php

mysql_select_db($database_konek, $konek);
$query_data_menu = "SELECT * FROM menu WHERE parent_m = 0 ORDER BY sortir_m ASC";
$data_menu = mysql_query($query_data_menu, $konek) or die(mysql_error());
$row_data_menu = mysql_fetch_assoc($data_menu);
$totalRows_data_menu = mysql_num_rows($data_menu);
 if ($totalRows_data_menu>0) { ?>
      <?php $i=1; do { 
$colname_p = "-1";
if (isset($row_data_menu['id'])) {
  $colname_p = $row_data_menu['id'];
}
mysql_select_db($database_konek, $konek);
$query_p = sprintf("SELECT * FROM menu WHERE parent_m = %s", GetSQLValueString($colname_p, "int"));
$p = mysql_query($query_p, $konek) or die(mysql_error());
$row_p = mysql_fetch_assoc($p);
$totalRows_p = mysql_num_rows($p);	
if ($totalRows_p==0){  
	  ?>
        <li><a href="<?php if ($row_data_menu['kemana']==1) { ?><?php echo $base_url ?>/h<?php echo $row_data_menu['id']."/".$row_data_menu['link_m']; ?><?php } else { ?><?php echo $row_data_menu['link_m']; ?><?php } ?>"><?php echo $row_data_menu['judul_m']; ?></a>
<?php
}

if ($totalRows_p>0){
?>
 <li class="dropdown" ><a href="<?php if ($row_data_menu['kemana']==1) { ?><?php echo $base_url ?>/h<?php echo $row_data_menu['id']."/".$row_data_menu['link_m']; ?><?php } else { ?><?php echo $row_data_menu['link_m']; ?><?php } ?>" class="dropdown-toggle" data-toggle="dropdown" ><?php echo $row_data_menu['judul_m']; ?> <b class="caret"></b></a>
<ul class="dropdown-menu">
		<?php do { 
$colname_p2 = "-1";
if (isset($row_p['id'])) {
  $colname_p2 = $row_p['id'];
}
mysql_select_db($database_konek, $konek);
$query_p2 = sprintf("SELECT * FROM menu WHERE parent_m = %s", GetSQLValueString($colname_p2, "int"));
$p2 = mysql_query($query_p2, $konek) or die(mysql_error());
$row_p2 = mysql_fetch_assoc($p2);
$totalRows_p2 = mysql_num_rows($p2);

if ($totalRows_p2==0){ 
		?>
		<li><a href="<?php if ($row_p['kemana']==1) { ?><?php echo $base_url ?>/h<?php echo $row_p['id']."/".$row_p['link_m']; ?><?php } else {  echo $row_p['link_m']; ?><?php } ?>"><?php echo $row_p['judul_m']; ?></a>

<?php
}

if ($totalRows_p2>0){
?>
<li class="dropdown-submenu"><a href="<?php if ($row_p['kemana']==1) { ?><?php echo $base_url ?>/h<?php echo $row_p['id']."/".$row_p['link_m']; ?><?php } else {  echo $row_p['link_m']; ?><?php } ?>"><?php echo $row_p['judul_m']; ?></a>
<ul class="dropdown-menu">
		<?php do { 
$colname_p3 = "-1";
if (isset($row_p2['id'])) {
  $colname_p3 = $row_p2['id'];
}
mysql_select_db($database_konek, $konek);
$query_p3 = sprintf("SELECT * FROM menu WHERE parent_m = %s", GetSQLValueString($colname_p3, "int"));
$p3 = mysql_query($query_p3, $konek) or die(mysql_error());
$row_p3 = mysql_fetch_assoc($p3);
$totalRows_p3 = mysql_num_rows($p3);

if ($totalRows_p3==0){
		?>
		<li><a href="<?php if ($row_p2['kemana']==1) { ?><?php echo $base_url ?>/h<?php echo $row_p2['id']."/".$row_p2['link_m']; ?><?php } else { echo $row_p2['link_m']; }?>"><?php echo $row_p2['judul_m']; ?></a>
        
 <?php
}

if ($totalRows_p3>0){
?>
<li class="dropdown-submenu" ><a href="<?php if ($row_p2['kemana']==1) { ?><?php echo $base_url ?>/h<?php echo $row_p2['id']."/".$row_p2['link_m']; ?><?php } else { echo $row_p2['link_m']; }?>"><?php echo $row_p2['judul_m']; ?></a>
<ul class="dropdown-menu">
		<?php do { 
$colname_p4 = "-1";
if (isset($row_p3['id'])) {
  $colname_p4 = $row_p3['id'];
}
mysql_select_db($database_konek, $konek);
$query_p4 = sprintf("SELECT * FROM menu WHERE parent_m = %s", GetSQLValueString($colname_p4, "int"));
$p4 = mysql_query($query_p4, $konek) or die(mysql_error());
$row_p4 = mysql_fetch_assoc($p4);
$totalRows_p4 = mysql_num_rows($p4);
if ($totalRows_p4==0){

		?>
		<li><a href="<?php if ($row_p3['kemana']==1) { ?><?php echo $base_url ?>/h<?php echo $row_p3['id']."/".$row_p3['link_m']; ?><?php } else { echo $row_p3['link_m']; }?>"><?php echo $row_p3['judul_m']; ?></a>

 <?php
}

if ($totalRows_p4>0){
?>
<li class="dropdown-submenu"><a href="<?php if ($row_p3['kemana']==1) { ?><?php echo $base_url ?>/h<?php echo $row_p3['id']."/".$row_p3['link_m']; ?><?php } else { echo $row_p3['link_m']; }?>"><?php echo $row_p3['judul_m']; ?></a>
<ul class="dropdown-menu" >
		<?php do { ?>
		<li><a href="<?php if ($row_p4['kemana']==1) { ?><?php echo $base_url ?>/h<?php echo $row_p4['id']."/".$row_p4['link_m']; ?><?php } else { echo $row_p4['link_m']; }?>"><?php echo $row_p4['judul_m']; ?></a>
        
         <?php echo "</li>"; } while ($row_p4 = mysql_fetch_assoc($p4)); 
		 mysql_free_result($p4); echo "</ul>"; }
		 ?>        

         <?php echo "</li>"; } while ($row_p3 = mysql_fetch_assoc($p3)); 
		 mysql_free_result($p3); echo "</ul>"; }
		 ?>
 
         <?php echo "</li>"; } while ($row_p2 = mysql_fetch_assoc($p2)); 
		 mysql_free_result($p2); echo "</ul>"; }
		 ?>        

         <?php echo "</li>"; } while ($row_p = mysql_fetch_assoc($p)); 
		 mysql_free_result($p); echo "</ul>"; }
		 ?>
         </li>
        <?php 
		
		} while ($row_data_menu = mysql_fetch_assoc($data_menu)); 
		?>
    <?php } ?>
<?php

mysql_free_result($data_menu);
?>
